package contorller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import entity.attendence;
import entity.department;
import service.attendenceService;
import service.departmentService;

@Controller
@RequestMapping("/attendence")
public class attendenceContorller {

	@Autowired
	private attendenceService attendenceService;
	@Autowired
	private departmentService departmentService;
	@RequestMapping(value = "/list",produces = {"application/json;charset=utf-8"})
	@ResponseBody
	public Map<String, Object> map(attendence attendence, int page,int limit) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		Page<attendence> pages=PageHelper.startPage(page, limit);
		List<attendence> list = attendenceService.getAll(attendence);
		map.put("count", pages.getTotal());
		map.put("data", list);
		map.put("code",0 );
		
		return map;
		
		
	}
	@RequestMapping(value = "/bumen",produces = {"application/json;charset=utf-8"})
	@ResponseBody
	public List<department> list() throws Exception{
		return departmentService.getAll();
		
		
	}
	
	
	@PostMapping("/add")
	public String add(attendence attendence) throws Exception{
			
		attendenceService.add(attendence);
		
		return "redirect:/NewFile.jsp";
		
		
	}
	@RequestMapping(value = "/delete", produces = { "application/json;charset=utf-8" })
	@ResponseBody
	public Map<String, Object> delete(Long[] ids) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		attendenceService.batchDelete(ids);
		map.put("result", true);
		return map;
	}
}
